import { ZilPayConnectedWallet } from "./ZilPayConnectedWallet";
export const ZilPayNetworkMap = {
  mainnet: 'mainnet',
  testnet: 'testnet',
}

export const connectWalletZilPay = async (zilPay) => {

  if (!zilPay.wallet.isConnect) //true or false
    throw new Error("ZilPay connection failed.");

  const account = zilPay.wallet.defaultAccount;
  if (!account)
    throw new Error("Please sign in to your ZilPay account before connecting.");

  const net = zilPay.wallet.net; //返回一个表示当前区块链网络 ID 的字符串。一些示例值：
  const network = ZilPayNetworkMap[net];
  if (!network)
    throw new Error(`Unsupported network for ZilPay: ${net}`);

  const wallet = new ZilPayConnectedWallet({
    network: new Date(),
    zilpay: zilPay,
    bech32: account?.bech32,
    base16: account?.base16,
  });

  return { wallet };
};